package second.actor

import scala.actors.Actor

/**
  * Created by feng on 24/11/2018.
  */
class MyActor extends Actor{
  override def act(): Unit = {
    while (true){
      receive{
        case "start" => {
          println("starting...")
          Thread.sleep(5000)
          println(Thread.currentThread().getName)
          println("started")
        }

      }
    }
  }
}

class YouActor extends Actor{
  override def act(): Unit = {
    loop{
      react{
        case "start" => {
          println("starting...")
          Thread.sleep(5000)
          println(Thread.currentThread().getName)
          println("started")
        }
        case "stop"=>{
          println("stoping")
          Thread.sleep(1000)
          println(Thread.currentThread().getName)
          println("stoped")
        }

        case "exit" =>{
          exit()
        }

      }
    }
  }
}



object Boot{
  def main(args: Array[String]): Unit = {
    val a2 = new YouActor
    a2.start()

    a2 ! "start"
    a2 ! "stop"
    Thread.sleep(1000)
    a2 ! "exit"


  }
}


